﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tomasulo_Simulator
{
    class Memory
    {
        private  long memorySize = long.MaxValue;
        private Dictionary<long, String> dataMemory;
        public Memory()
        {
            dataMemory = new Dictionary<long, String>();
        }

        public Memory(int size)
        {
            memorySize = size;
            dataMemory = new Dictionary<long, String>(size);
        }

        public void storeWord(String data, long location)
        {
    
            if (location > memorySize || location < 0)
                throw new IndexOutOfRangeException("Memory index of of range");
            try
            {
                dataMemory.Add(location, data);
            }
            catch (ArgumentException e)
            {
                dataMemory[location] = data;
            }
                
        }

        public String loadWord(long location)
        {
            String value;
            if (location > memorySize || location < 0 )
                throw new IndexOutOfRangeException("Memory index of of range");

            dataMemory.TryGetValue(location, out value);
            return value;

        }
    }
}
